package com.oa.resources.base.restful;

import com.oa.resources.base.restful.enums.RtCodeType;
import com.oa.resources.base.restful.inter.BaseReturn;
import com.oa.resources.consts.AppConsts;
import com.oa.resources.util.JsonUtil;

/**
 * Restful返回对象,抽象类
 * @author G20
 *
 */
public class RtMsg implements BaseReturn{
	
	private Integer code;
	
	private String msg;
	
	private Object responseBody;
	
	public Integer getCode() {
		return code;
	}
	
	public RtMsg setCode(RtCodeType type) {
		if(type.getIndex() == AppConsts.RT_CODE_VALIDATOR){
			msg = "校验异常.";
		}else if(type.getIndex() == AppConsts.RT_CODE_SUCCESS){
			msg = "操作成功.";
		}else if(type.getIndex() == AppConsts.RT_CODE_ERROR){
			msg = "后台异常.";
		}
		this.code = type.getIndex();
		return this;
	}
	
	public String getMsg() {
		return msg;
	}
	
	public void setMsg(String msg) {
		this.msg = msg;
	}
	
	public Object getResponseBody() {
		return responseBody;
	}
	
	public void setResponseBody(Object responseBody) {
		this.responseBody = responseBody;
	}
	
	@Override
	public String toString(){
		return JsonUtil.toJSONString(this);
	}
}
